LBB

UserAgent 混乱无序,每个浏览器为了兼容都在伪装成其他浏览器

# UserAgent 混乱无序,每个浏览器为了兼容都在伪装成其他浏览器 最近业余时间写了一个检查用户浏览器支持的最佳图片格式的库 [optimal-img-format](https://github.com/lbb00/optimal-img-format),在 SSR 的时候检查 Header 中的 User-Agent 从而大致判断出浏览器支持哪种最佳的类型。于是写了一个简单的页面,用于查看当前的浏览器的 User-Agent,这些 UA 中有些很奇怪的字段,比如都以 Mozilla/5.0 开头。然后就找到这篇关于 [User Agent 历史](https://webaim.org/blog/user-agent-string-history) 的文章,文中介绍了浏览器厂商为了获得更好的兼容使用 UA 伪装其他浏览器,最终导致了 UA 的混乱。 另外在 MDN 关于 UA 的介绍中不推荐使用 UA 进行浏览器检测,我觉有一部分原因也是因为早期服务端返回 HTML 会根据 UA 来处理兼容,浏览器 UA 为了兼容去伪装最终导致了混乱。 拓展: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent https://en.wikipedia.org/wiki/KHTML https://en.wikipedia.org/wiki/Gecko_(software) https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/User-Agent/Firefox https://stackoverflow.com/questions/10847390/in-http-user-agent-header-of-android-what-does-the-u-mean 工具: https://www.useragentstring.com/
UserAgent 混乱无序,每个浏览器为了兼容都在伪装成其他浏览器 | LBB